package com.xuhai.blog.common.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @Author PangJunjie
 * @Date 2022/2/8/008
 */
@Configuration
public class KaptchaConfig {
    @Bean
    public DefaultKaptcha getDefaultKaptcha(){
        /*初始化验证码生成器*/
        DefaultKaptcha defaultKaptcha=new DefaultKaptcha();
        /*初始化属性配置类*/
        Properties properties=new Properties();
        /*设置验证码是否有边框*/
        properties.setProperty("kaptcha.border","yes");
        /*设置验证码文本颜色*/
        properties.setProperty("kaptcha.textproducer.font.color","black");
        /*设置验证码长度*/
        properties.setProperty("kaptcha.textproducer.char.length","4");
        /*初始化验证码配置类并装载配置*/
        Config config=new Config(properties);
        /*装载配置到生成器*/
        defaultKaptcha.setConfig(config);
        /*输出验证码*/
        return defaultKaptcha;
    }
}
